package homework.qingming.calc.functions;

import homework.util.BigDecimalMath;

import java.math.BigDecimal;

public class SqrtFunction extends BaseFunction {

    public SqrtFunction() {
        super("sqrt", 1);
    }

    @Override
    public BigDecimal function(BigDecimal... v) {
        if(v[0].compareTo(BigDecimal.ZERO) < 0) {
            throw new ArithmeticException("被开方数必须大于0");
        }
        return BigDecimalMath.sqrt(v[0]);
    }
}
